#ifndef VORONOI_DEFS

#define VORONOI_DEFS

#include "geometry.h"
#include "polygon.h"

typedef struct {
	Pt	from, to;
	}	SegStruct;

typedef struct {
	Pt		centre, fromPt, toPt; /* From and to are ccw around the circle. */
	Real	radius;
	}	CircStruct;

#define ParaType	1
#define SegType		2
#define CircType	3

typedef struct _curve {
	int		type;
	union {
		Parabola	para;
		SegStruct	seg;
		CircStruct	circle;
	}	data;
	struct _curve	*next;
	}	Curve;

typedef struct {
	Pt	attachment, otherPt;
	Pgon *attachPolygon;
	int	attachIndex;
	}	spokeInfo;

#define NormalVoronoi	1
#define InfiniteVoronoi	0

typedef struct {
	int		type;
	Pt		voronoi;
	Pt		attachment[3];
	int		attachIdx[3];
	Pgon	*generator[3];
	Curve	*bisector[3];	/*	entry i between bisectors to i and i+1.  */
	Curve	*bottleneck[3];
	}	storedVoronoi;

#ifdef __cplusplus
extern "C" {
#endif

boolean voronoiVertex(Pgon *a, Pgon *b, Pgon *c, Pt *vorPoint, Pt
	*eventPoint, spokeInfo *middleSpoke);
int recordVoronoiVertex (Pt *point, spokeInfo *spoke1, spokeInfo
	*spoke2, spokeInfo *spoke3);

void initVoronoi(int limit);
void endVoronoi();
void printVoronoiEdges (Pgon **polyList, int numPoly);
void printBottlenecks (Pgon **polyList, int numPoly);
void printSpokes();
void printVoronoiVertices();

void ptNearestPgon (Pt *point, Pgon *poly, Pt *nearest);

void findSpoke(Pt *origin, Pgon *object, spokeInfo *spoke);

#ifdef __cplusplus
}
#endif

#endif
